/*
 * 文件名称: Result.java Copyright 2011-2016 Ximalaya All right reserved.
 */
package top.zxybird.yun.rpc.api;

/**
 * Result with specified type
 *
 * @author Ted Wang
 */
public class Result {

  public Result() {
  }

  private Object value;

  // only used for server @see
  // com.ximalaya.mainstay.rpc.proxy.jdk.JdkProxyFactory.CachedInvoker#doInvoke
  private Throwable exception = null;
  private boolean isSuccess = true;

  public Throwable getException() {
    return exception;
  }

  public void setException(Throwable exception) {
    this.exception = exception;
    this.isSuccess = false;
  }

  public boolean isSuccess() {
    return isSuccess;
  }

  public void set(Object value) {
    this.value = value;
  }

  // 对于server 来说 get 出来的 是iface 的 return 类型
  // 对于client 来说，一般都用 ifutureFace, 类型都是Future, 而且，exception 永远为null
  public Object get() throws Throwable {
    if (exception != null) {
      throw exception;
    }
    return value;
  }
}
